<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/tweeningparameter.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<META http-equiv="Content-Type" content="text/html; charset=">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Tweener Documentation and Language Reference</title>
<!-- InstanceEndEditable -->
<link href="../style.css" rel="stylesheet" type="text/css">
<link href="../print.css" rel="stylesheet" type="text/css" media="print">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!-- InstanceParam name="OptionalSeeAlso" type="boolean" value="true" --><!-- InstanceParam name="OptionalNotes" type="boolean" value="true" -->
</head>
<body>
<div id="header">
  <p>Tweener Documentation</p>
  <h1><!-- InstanceBeginEditable name="PageType" -->Reference &raquo; Tweening Parameters<!-- InstanceEndEditable --></h1>
</div>
<div class="detailBody">
  <h1><!-- InstanceBeginEditable name="ParameterName" -->onStart<!-- InstanceEndEditable --></h1>
  <h4>Availability</h4>
  <!-- InstanceBeginEditable name="DetailAvailability" -->
  <p>AS2 and AS3.</p>
  <!-- InstanceEndEditable -->
  <h4>Usage</h4>
  <pre><!-- InstanceBeginEditable name="DetailUsage" -->... onStart:value<!-- InstanceEndEditable -->, ...</pre>
  <h4>Parameters</h4>
  <!-- InstanceBeginEditable name="DetailParameters" -->
  <p><code>value</code>:Function &mdash; A function that is called immediately before a tweening starts. It is called once regardless of the number of properties involved on the tweening. The function scope (in which the event is executed) is the target object itself, unless specified by the <code><a href="onStartScope.html">onStartScope</a></code> parameter.</p>
  <!-- InstanceEndEditable -->
  <h4>Examples</h4>
  <!-- InstanceBeginEditable name="DetailExamples" -->
  <pre>// Hides a movieclip, then only shows it when it's time for it to fade in (AS2)
showUp = function() {
	this._visible = true;
};
myMovieClip._visible = false;
myMovieClip._alpha = 0;
Tweener.addTween(myMovieClip, {_alpha:100, time:1, delay:4, onStart:showUp});</pre>
  <pre>// Similarly, with an anonymous function
myMovieClip._visible = false;
myMovieClip._alpha = 0;
Tweener.addTween(myMovieClip, {_alpha:100, time:1, delay:4, onStart:function() { this._visible = true; }});</pre>
  <!-- InstanceEndEditable -->
  
  <h4><a name="notes">Notes</a></h4>
  <!-- InstanceBeginEditable name="DetailsNotes" -->
  <p>The reference passed to this property is a reference to the function <strong>only</strong>. This roughly means you do <strong>not</strong> use any kind of parenthesis or parameters when passing the function you wish to call - you need to use the <a href="onStartParams.html">onStartParams</a> parameter for that. For example, this is wrong:</p>
  <pre>Tweener.addTween(myMC, {_x:10, time:1, onStart:myFunction(), delay:1});
</pre>
  <p>What the above code would do is immediately call the <code>myFunction</code> function, regardless of any time or delay imposed, and actually pass its return value (if any) as the <code>onStart</code> parameter for Tweener. That is, it won't work, and that's not the way actionscript is meant to work. The correct code is as such: </p>
  <pre>Tweener.addTween(myMC, {_x:10, time:1, onStart:myFunction, delay:1});
</pre>
  <p>This way, you are passing the function itself as the parameter.</p>
  <p>In the same vein, you <strong>cannot</strong> pass parameters for a function by enclosing it with parenthesis. This won't work:</p>
  <pre>Tweener.addTween(myMC, {_x:10, time:1, onStart:trace(&quot;I've started!&quot;), delay:1});
</pre>
  <p>Again, it will call the function immediately, and pass its return value (if any) as the actual parameter. That's usually not what you want to do. The correct way to pass function parameters is with an additional tweening parameter -- as mentioned, <code>onStartParams</code> on this case. This way:</p>
  <pre>Tweener.addTween(myMC, {_x:10, time:1, onStart:trace, onStartParams:[&quot;I've started!&quot;], delay:1});
</pre>
  <p>And remember that, of course, you can always use function calls on any tweening parameter, as long as you know what you're doing - that is, you expect the function to be called immediately and its return value to be the actual tweening parameter used. For example, to get a random destination as a parameter:</p>
  <pre>var getRandomPosition:Function = function(): Number {
	return Math.random() * 400;
};
Tweener.addTween(myMC, {_x:getRandomPosition(), time:1});
</pre>
  <!-- InstanceEndEditable -->
  
  <h4>See also</h4>
  <!-- InstanceBeginEditable name="DetailsSeeAlso" -->
  <p><a href="onStartParams.html">onStartParams</a>, <a href="onStartScope.html">onStartScope</a>, <a href="onUpdate.html">onUpdate</a>, <a href="onComplete.html">onComplete</a>, <a href="onOverwrite.html">onOverwrite</a></p>
  <!-- InstanceEndEditable --></div>
</body>
<!-- -->
<!-- InstanceEnd --></html>
